package com.zoe.thread.th15_CAS;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author Zoe
 * @Date: 2021/05/07
 * @Description
 */
public class CASDemo {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(2020);
        // cas(期望值,更新值)
        // 如果变量当前值和期望值一样，则更新；
        // 就像git一样，提交之前先拉取看看有没有冲突，有冲突则更新失败；

        boolean b = atomicInteger.compareAndSet(2020, 2021);
        boolean b1 = atomicInteger.compareAndSet(2020, 2026);
        System.out.println(b);
        System.out.println(b1);
    }
}
